/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ISDSNN_1_DSC;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;

/**
 *
 * @author francisco
 */
public class MyThread extends Thread {
    private String comando;
    private static File file;
    private static FileInputStream fis;
    private static BufferedInputStream bis;
    private static DataInputStream dis;
    private static ArrayList<String> com;
    private static String fileDir;
    public MyThread(String comando)
    {
        this.comando=comando;
    }
    
    public MyThread()
    {
    }
    
    public void setFileDir(String fileDir){
        this.fileDir = fileDir;
    }

    public void run() {
       try
       {
           System.out.println(comando);
            Process p = Runtime.getRuntime().exec(comando);
            BufferedReader stdInput = new BufferedReader(new 
                 InputStreamReader(p.getInputStream()));
            BufferedReader stdError = new BufferedReader(new 
                 InputStreamReader(p.getErrorStream()));
            System.out.println("NmapWorking\n");
            while ((comando = stdInput.readLine()) != null) {
                System.out.println(comando);
            }
            System.out.println("Error\n");
            while ((comando = stdError.readLine()) != null) {
                System.out.println(comando);
            }
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {    
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public void main() 
    {
        Thread thread;
        com = new ArrayList<String>();
        readFile();
        for(String command : com)
        {
         thread = new MyThread(command);
         thread.start();
        }
    }
    
    private static void readFile()
    {
        try
        {
            file = new File(fileDir);
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            dis = new DataInputStream(bis);
            while(dis.available()!=0)
            {
                com.add(dis.readLine());
            }
            fis.close();
            bis.close();
            dis.close();
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {
        }
    }
}